<?php


namespace app\common\model;


use think\facade\Db;
use think\Model;

/**
 * 用户模型
 * @package app\common\model
 * @method static getavatar()
 */
class User extends Model
{
    protected $table = "ea_member";
    /**
     * 获取用户基本信息
     * @param $userid  用户id
     * @return array|\think\Model|null
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getinfo($userid)
    {
        $info = Db::table('ea_member')->alias('e')
            ->join('member_detail m','e.id = m.member_id')
            ->where('e.id',$userid)
            ->field('e.id,e.name,e.education_level,e.phone,e.sex,
            e.participation_time,e.identity,e.wx_id,e.birthday,e.default_identity,m.advantage,m.working_status,e.email,e.avatar
            ')
            ->find();

        if (!$info['name']) $info['name'] = "牛人";
        // 求职意向
        $info['objective'] = objective($userid);
        // 工作经历
        $info['experience'] = experience($userid);
        // 教育经历
        $info['educationa'] = educationa($userid);

        foreach ($info['experience'] as $key => $value) {
            $info['experience'][$key]['area_no'] = (int) $value['area_no'];
        }

        // 经验
        $info['participation_num'] = $info['participation_time'] ? diffDate($info['participation_time'],time()) : 0;
        // 年龄
        $info['birthday_num'] = $info['birthday'] ? diffDate($info['birthday'],time()) : 0;

        // 出生年月
        if ($info['birthday']) {
            $info['birthday'] = date("Y-m-d",$info['birthday']);
        }
        // 参加工作时间
        if ($info['participation_time']) {
            $info['participation_time'] = date("Y-m-d",$info['participation_time']);
        }

        $info['sex'] = sextype($info['sex']);
        $info['working_status'] = workingstatus($info['working_status']);
        $info['identity'] = identitytype($info['identity']);
        $info['education_level'] = education_level($info['education_level']);

        return $info;
    }

    /**
     * 获取用户头像
     * @param  [type] $userid [description]
     * @return [type]         [description]
     */
    public static function getavatar($userid)
    {
        return self::where('id',$userid)->value('avatar');
    }
}
